package com.wzy.server.config;

import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @title: RedisConfig
 * @projectName yeb
 * @description: TODO
 */
@Api("redis配置类")
@Configuration
public class RedisConfig {
//    序列化rediss
    @Bean
    public RedisTemplate<String,Object> getBean(RedisConnectionFactory factory){
        RedisTemplate<String, Object> template = new RedisTemplate();
//        放置工厂
        template.setConnectionFactory(factory);
        //        String类型key序列器
        template.setKeySerializer(new StringRedisSerializer());
        //        String类型value序列器
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        //        Hash类型key序列器
        template.setHashKeySerializer(new StringRedisSerializer());
        //        Hash类型key序列器
        template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
        return template;
    }
}
